#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int p[N],n,m,op,x,y;
int find(int x)
{
    if (p[x] != x) p[x] = find(p[x]);
    return p[x];
}
int main()
{
	close();
	cin>>n>>m;
	for(int i=1;i<=n;i++) p[i]=i;
		
	while(m--)
	{
		cin>>op>>x>>y;
		if(op==1) p[find(x)] = find(y);
		else
		{
			if(find(x)==find(y)) cout<<"YES"<<'\n';
			else cout<<"NO"<<'\n';
		} 
	}
	return 0;
}